/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package edu.ccut.titan.component;

import java.io.File;
import java.net.URL;
import java.util.Vector;

import junit.framework.TestCase;

import org.easymock.EasyMock;
import org.osgi.framework.Bundle;

public class AbstractCompnentTestCase extends TestCase {

	protected Bundle mockBundle = null;

	protected URL titanComponentURL = null;

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		// mock a bundle use in this module test
		this.mockBundle = EasyMock.createMock(Bundle.class);

		String[] files = new File(AbstractCompnentTestCase.class.getResource(
				"/").getPath()).list();

		Vector<String> fileVector = new Vector<String>();
		for (String file : files) {
			fileVector.add(file + "/");
		}

		EasyMock.expect(this.mockBundle.getEntryPaths("/")).andReturn(
				fileVector.elements()).times(0, 20);

		EasyMock.expect(
				this.mockBundle.getEntry("META-INF/titan-component.xml"))
				.andReturn(
						AbstractCompnentTestCase.class
								.getResource("/META-INF/titan-component.xml"))
				.times(0, 20);

		EasyMock.expect(
				this.mockBundle.getEntry("logic/validateUser.logic.xml"))
				.andReturn(
						AbstractCompnentTestCase.class
								.getResource("/logic/validateUser.logic.xml"))
				.times(0, 20);

		EasyMock
				.expect(
						this.mockBundle
								.getEntry("action/validateUser.action.xml"))
				.andReturn(
						AbstractCompnentTestCase.class
								.getResource("/action/validateUser.action.xml"))
				.times(0, 20);

		EasyMock
				.expect(
						this.mockBundle
								.getEntry("component/GetPasswordTestComponent.component.xml"))
				.andReturn(
						AbstractCompnentTestCase.class
								.getResource("/component/GetPasswordTestComponent.component.xml"))
				.times(0, 20);
		
		EasyMock
		.expect(
				this.mockBundle
						.getEntry("component/GetUsernameTestComponent.component.xml"))
		.andReturn(
				AbstractCompnentTestCase.class
						.getResource("/component/GetUsernameTestComponent.component.xml"))
		.times(0, 20);
		
		EasyMock
		.expect(
				this.mockBundle
						.getEntry("component/ShowResultTestComponent.component.xml"))
		.andReturn(
				AbstractCompnentTestCase.class
						.getResource("/component/ShowResultTestComponent.component.xml"))
		.times(0, 20);
		
		EasyMock
		.expect(
				this.mockBundle
						.getEntry("component/ValidateUserComponent.component.xml"))
		.andReturn(
				AbstractCompnentTestCase.class
						.getResource("/component/ValidateUserComponent.component.xml"))
		.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("page/.titan")).andReturn(
				AbstractCompnentTestCase.class.getResource("/page/.titan"))
				.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("logic/.titan")).andReturn(
				AbstractCompnentTestCase.class.getResource("/logic/.titan"))
				.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("action/.titan")).andReturn(
				AbstractCompnentTestCase.class.getResource("/action/.titan"))
				.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("component/.titan"))
				.andReturn(
						AbstractCompnentTestCase.class
								.getResource("/component/.titan")).times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("edu/.titan")).andReturn(null)
				.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("META-INF/.titan")).andReturn(
				null).times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("log4j.properties/.titan"))
				.andReturn(null).times(0, 20);

		EasyMock.expect(
				this.mockBundle.loadClass(GetPasswordTestComponent.class
						.getName())).andReturn(GetPasswordTestComponent.class)
				.times(0, 20);

		EasyMock.expect(
				this.mockBundle.loadClass(GetUsernameTestComponent.class
						.getName())).andReturn(GetUsernameTestComponent.class)
				.times(0, 20);

		EasyMock.expect(
				this.mockBundle.loadClass(ShowResultTestComponent.class
						.getName())).andReturn(ShowResultTestComponent.class)
				.times(0, 20);

		EasyMock.expect(
				this.mockBundle
						.loadClass(ValidateUserComponent.class.getName()))
				.andReturn(ValidateUserComponent.class).times(0, 20);

		EasyMock.expect(this.mockBundle.loadClass(String.class.getName()))
				.andReturn(String.class).times(0, 20);

		EasyMock.expect(this.mockBundle.loadClass(Boolean.class.getName()))
				.andReturn(Boolean.class).times(0, 20);

		EasyMock.expect(this.mockBundle.getSymbolicName()).andReturn(
				"edu.ccut.titan.component").times(0, 20);

		EasyMock.replay(this.mockBundle);
	}
}
